cmake_minimum_required(VERSION 2.8)
project (ccORM)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CompilerOptions.cmake)
if (MSVC)
  set(VCPKG_ROOT D:/C++/vcpkg/packages)
  add_compile_options( /Oi /Ox /GA /W3 /permissive- /utf-8 /std:c++17 )
else()
  set(VCPKG_ROOT /home/asciphx/vcpkg/packages)
  #set(CMAKE_CXX_COMPILER ${tools}/bin/g++)
  add_compile_options( -g -m64 -pthread -static-libgcc -std=c++17)
endif()
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
find_package(MYSQL REQUIRED)
find_package(PostgreSQL REQUIRED)
find_package(SQLite3 REQUIRED)
find_package(ZLIB)
find_package(OpenSSL)
if(OpenSSL_FOUND)
	include_directories(${OPENSSL_INCLUDE_DIR})
	set(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
else()
  set( OPENSSL_ROOT_DIR ${VCPKG_ROOT}/openssl_x64-linux)
  set( OPENSSL_INCLUDE_DIR ${VCPKG_ROOT}/openssl_x64-linux/include)
  set( OPENSSL_SSL_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libssl.a)
  set( OPENSSL_CRYPTO_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libcrypto.a)
  set( OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
  include_directories(${OPENSSL_INCLUDE_DIR})
endif()
if (NOT CMAKE_BUILD_TYPE)
	message(STATUS "No build type selected, default to Release")
	set(CMAKE_BUILD_TYPE "Release")
endif()
if (MSVC)
	SET(BOOST_ROOT "E:/Code/boost_1_75_0")
	set(Boost_USE_STATIC_LIBS "On")
	find_package( Boost 1.55 COMPONENTS system REQUIRED )
  set(LIBS ${Boost_LIBRARIES} ${MYSQL_LIBRARY} ${SQLite3_LIBRARIES} ${PostgreSQL_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARY} wsock32 ws2_32 )
else()
	find_package( Boost 1.55 COMPONENTS system thread REQUIRED )
  set(LIBS ${Boost_LIBRARIES} ${MYSQL_LIBRARY} ${SQLite3_LIBRARIES} ${PostgreSQL_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARY} dl )
endif()
include_directories( ${Boost_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR} ${SQLite3_INCLUDE_DIRS} ${PostgreSQL_INCLUDE_DIRS})
#add_subdirectory(src)
add_executable(ccORM main.cpp)
target_link_libraries( ccORM ${LIBS})
add_custom_command(OUTPUT any.db
	COMMAND ${CMAKE_COMMAND} -E
copy ${PROJECT_SOURCE_DIR}/any.db ${CMAKE_CURRENT_BINARY_DIR}/any.db
	DEPENDS ${PROJECT_SOURCE_DIR}/any.db
)
add_custom_target(any_copy ALL DEPENDS any.db)
